package com.hw.protocol.tool.controller.transform;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hw.protocol.tool.model.entity.MeterData;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : lihy
 * @date : 2024/3/14 15:10
 * description:
 */

public abstract class AbsTransform {

    static String getJson(List<MeterData> meterDataList){
        List<JSONObject> list = meterDataList.stream().map(md -> new JSONObject(md, new JSONConfig().setDateFormat("yyyy-MM-dd HH:mm:ss")))
                .collect(Collectors.toList());
        /*if (CollectionUtil.isNotEmpty(meterDataList)) {
            JSONObject jsonObject = new JSONObject(meterDataList, new JSONConfig().setDateFormat("yyyy-MM-dd HH:mm:ss"));
            return JSONUtil.toJsonStr(jsonObject).replace(",", ",\n");
        }*/
        return JSONUtil.toJsonStr(list).replace(",", ",\n");
    }
}
